import chroma from "chroma-js";

/** 混合颜色的算法,a1,a1 不同时为 0 */
export function blendColor(
    color1: number,
    a1: number,
    color2: number,
    A2: number
): [number, number] {
    const [R1, G1, B1] = chroma(color1).rgb();
    const [R2, G2, B2] = chroma(color2).rgb();
    const a2 = A2 - (a1 * A2) / 255;
    const a = a1 + a2;

    const R = (a1 * R1 + a2 * R2) / a;
    const G = (a1 * G1 + a2 * G2) / a;
    const B = (a1 * B1 + a2 * B2) / a;
    const newOne = chroma.rgb(R, G, B);
    return [newOne.num(), a];
}
